<template>
  <el-dialog
				title="提示"
				:visible.sync="params.dialogVisible"
				width="30%"
				:before-close="handleClose">
    <slot name="txt-before"></slot>
    <span><slot name="txt"></slot></span>
    <slot name="txt-after"></slot>
    <span slot="footer" class="dialog-footer">
      <slot name="button-before"></slot>
      <el-button type="primary" @click="submitOk">同 意</el-button>
      <el-button type="primary" @click="submitClose">驳 回</el-button>
      <el-button @click="handleClose">取 消</el-button>
      <slot name="button-after"></slot>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    props: ['params'],
    methods: {
      submitAll (state, stateContent, success, info) {
        let __axios = this.$axios.create()
        __axios.interceptors.response.use(response => response)
        
        __axios.get(this.$api.updateCarState, {params: {
          carId: this.params.item.carId,
          stateKey: 'carStockState',
          stateValue: state,
          content: stateContent || '',
          userId: this.$sess.get('userInfo').userId
        }}).then(res => {
          if (res.data.code == 1) {
            this.$message({type: 'success', message: success || '修改成功'})
          } else if (res.data.code == 2) {
            this.$message({type: 'info', message: '修改失败:' + res.data.msg })
          } else {
            this.$message({type: 'info', message: info || '修改失败'})
          }
          this.handleClose()
        })
      },
      // 成功
      submitOk () {
        this.submitAll(20, null, '入库成功', '入库失败')
      },
      // 驳回
      submitClose () {
        this.$prompt('请输驳回原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPlaceholder: '请输入驳回原因',
          inputPattern: /^\S{1,200}/,
          inputErrorMessage: '驳回原因不能为空，不能超过200字符'
        }).then(({ value }) => {
          // return false;
          this.submitAll (1, value, '驳回成功', '驳回失败')
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消驳回'
          });
          this.handleClose()
        });
      },
      handleClose () {
        this.params.dialogVisible = false
      }
    }
  }
</script>
